package MyIOtest;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class Test4 {
    //需求：把文件的数据排序
    //2-1-7-9-8
    //1-2-7-8-9
    public static void main(String[] args) throws IOException {
        //写入数据
        FileReader fr=new FileReader("D:\\javacode\\test\\c.txt");
        StringBuilder sb=new StringBuilder();
        int ch;
        while((ch=fr.read())!=-1){
            sb.append((char)ch);
        }
        fr.close();
        System.out.println(sb);
        //排序

        Integer[] arr = Arrays.stream(sb.toString()
                .split("-"))
                .map(Integer::parseInt)
                .sorted()
                .toArray(Integer[]::new);
        System.out.println(arr.toString());
        //写出

        FileWriter fw=new FileWriter("D:\\javacode\\test\\c.txt");
        String replace = Arrays.toString(arr).replace(",", "-");
        String result = replace.substring(1, replace.length() - 1);
        fw.write(result);
        fw.close();

    }

}
